package com.yizhi.student.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.yizhi.student.dao.StudentInfoDao;
import com.yizhi.student.domain.StudentInfoDO;
import com.yizhi.student.service.StudentInfoService;


@Service
public class StudentInfoServiceImpl implements StudentInfoService {


    @Autowired
    private StudentInfoDao studentInfoDao;

    @Override
    public StudentInfoDO get(Integer id) {
        System.out.println("======service层中传递过来的id参数是：" + id + "======");
        return studentInfoDao.get(id);
    }


    @Override
    public List<StudentInfoDO> list(Map<String, Object> params) {
        int currPage = Integer.parseInt((String) params.get("currPage"));
        int pageSize = Integer.parseInt((String) params.get("pageSize"));
        Integer offset = (currPage - 1) * pageSize;
        if (!params.containsKey("name")) {
            params.put("name", null);
        }
        if (!params.containsKey("tocollegeId")) {
            params.put("tocollegeId", null);
        }
        if (!params.containsKey("tomajorId")) {
            params.put("tomajorId", null);
        }
        if (!params.containsKey("classId")) {
            params.put("classId", null);
        }
        Integer tocollegeId = (params.get("tocollegeId") == null) || "".equals(((String) params.get("tocollegeId"))) ? null : Integer.parseInt((String) params.get("tocollegeId"));
        Integer tomajorId = params.get("tomajorId") == null || "".equals(((String) params.get("tomajorId"))) ? null : Integer.parseInt((String) params.get("tomajorId"));
        Integer classId = params.get("classId") == null || "".equals(((String) params.get("classId"))) ? null : Integer.parseInt((String) params.get("classId"));
        String name = params.get("name") == null || "".equals(((String) params.get("name"))) ? null : (String) params.get("name");
        return studentInfoDao.list(offset, pageSize, name, tocollegeId,
                tomajorId, classId);
    }

    //"===================================================================================="


    @Override
    public int count() {
        return studentInfoDao.count();
    }

    @Override
    public int save(StudentInfoDO studentInfo) {
        return studentInfoDao.save(studentInfo);
    }

    @Override
    public int update(StudentInfoDO studentInfo) {
        return studentInfoDao.update(studentInfo);
    }

    @Override
    public int remove(Integer id) {
        return studentInfoDao.remove(id);
    }

    @Override
    public int batchRemove(Integer[] ids0) {
        List<Integer> ids= Arrays.stream(ids0).collect(Collectors.toList());
        return studentInfoDao.batchRemove(ids);
    }

}
